package com.nervenets.web.controller.handler.admin.movie;

import com.nervenets.web.controller.handler.SessionHandler;
import com.nervenets.web.controller.handler.common.IdTokenParams;
import com.nervenets.web.entity.MessageCode;
import com.nervenets.web.enumeration.Role;
import com.nervenets.web.hibernate.domain.film.Movie;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

public class MovieDetailForManagerHandler extends SessionHandler<IdTokenParams> {
    @Override
    public ArrayList<Role> allowRoles() {
        return Role.issues();
    }

    @Override
    public boolean needLog() {
        return false;
    }

    @Override
    public String handle(IdTokenParams params, HttpServletRequest request) throws Exception {
        final Movie movie = userDao.findById(params.getTargetId(), Movie.class);
        if (null == movie) return errorMessage(MessageCode.code_404, "影片不存在");
        long salesOfMoney = globalService.getMovieBuyMoney(movie.getId());
        return successMessage(movie, new KeyValue("salesOfMoney", salesOfMoney), new KeyValue("user", globalService.getUser(movie.getUserId())));
    }

    @Override
    public String result() throws Exception {
        return successMessage("影片原始信息");
    }
}
